package com.xzbd.gef.view;


import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.text.BlockFlow;
import org.eclipse.draw2d.text.FlowPage;
import org.eclipse.draw2d.text.ParagraphTextLayout;
import org.eclipse.draw2d.text.TextFlow;

import com.xzbd.core.SerializableColor;


public class TextNodeFigure  extends Figure {
	TextFlow labelNotes;
	
	public TextNodeFigure() {
		ToolbarLayout layout = new ToolbarLayout();
        setLayoutManager(layout);
        
        FlowPage page = new FlowPage();
        page.setForegroundColor(ColorConstants.black);
        setBackgroundColor(ColorConstants.white);
        BlockFlow block = new BlockFlow();
        labelNotes = new TextFlow();
        labelNotes.setLayoutManager(new ParagraphTextLayout(labelNotes,ParagraphTextLayout.WORD_WRAP_SOFT));
        block.add(labelNotes);
        page.add(block);
        setOpaque(true);
        add(page);
	}
	
	public void setColor(SerializableColor color){
		setBackgroundColor(color.getColor());
	}
	
	public void setNotes(String text) {
		labelNotes.setText(text);
	}
	
	public void setLayout(Rectangle rect) {
		getParent().setConstraint(this, rect);
	}
}